package com.xiaomeng.principle.demeter.improve;

import java.util.ArrayList;
import java.util.List;

public class Demeter1 {

    public static void main(String[] args) {
        SchoolManager schoolManager = new SchoolManager();
        schoolManager.printAllEmployee(new CollegeManager());
    }
}
// 学校总部员工
class Employee {
    private String id;
    public void setId(String id) {
        this.id = id;
    }
    public String getId() {
        return id;
    }
}
// 学院员工类
class CollegeEmployee {
    private String id;
    public void setId(String id) {
        this.id = id;
    }
    public String getId() {
        return id;
    }
}
// 管理学院员工的管理类
class CollegeManager {
    // 返回学院的所有员工
    public List<CollegeEmployee> getAllEmployee() {
        List<CollegeEmployee> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) { // 增加了10个员工
            CollegeEmployee emp = new CollegeEmployee();
            emp.setId("学院员工id=" + i);
            list.add(emp);
        }
        return list;
    }
    // 改进: 将输出学院员工的方法封装到CollegeManager中
    //    怎么实现的,自己去写,不要再在其他类中体现
    public void printAllEmployee() {
        List<CollegeEmployee> list1 = this.getAllEmployee();
        System.out.println("---------分公司员工-------------");
        list1.forEach(e -> System.out.println(e.getId()));
    }
}
// 学校管理类
class SchoolManager {
    // 返回学校总部的员工
    public List<Employee> getAllEmployee() {
        List<Employee> list = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Employee emp = new Employee();
            emp.setId("学校总部员工id=" + i);
            list.add(emp);
        }
        return list;
    }
    // 该方法输出学校总部和学院员工信息(id)
    public void printAllEmployee(CollegeManager sub) {
        sub.printAllEmployee();

        List<Employee> list2 = this.getAllEmployee();
        System.out.println("----------学校总部员工----------");
        list2.forEach(e -> System.out.println(e.getId()));
    }
}


